/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.servlets;

import javax.ejb.EJB;
import java.util.Properties;
import ecom.beans.session.EcomAdminRemote;
import ecom.beans.entity.Accounts;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.Table;
import ecom.beans.session.EcomAdminBean;


/**
 *
 * @author Mariam Soumar�
 */
public class InitDataBaseTest {

    public InitDataBaseTest() {
        //
    }
@EJB
 public static EcomAdminRemote dao;

   

    public static void init() throws NamingException {
        // initialisation environnement JNDI
                       Properties props = new Properties();

			props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");

			props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");

			props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
			//props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");


        InitialContext initialContext = new InitialContext(props);
       // instanciation couche dao
       System.out.println("mmmmmmmmmmmmmm "+EcomAdminRemote.class.getName()  +" ffffffffffffffff");
       System.out.println("test "+initialContext.toString()+"test");
            dao = (EcomAdminRemote) initialContext.lookup("ecom.beans.session.EcomAdminRemote");
        
    }

    

    /**
     * Test of main method, of class InitDataBase.
     */
   
    public static void Main() throws Exception {
        // affichage m�decins
        List<Accounts> counts = null;
        try {
            counts = dao.getAllAccount();
            display("Liste des comptes :", counts);
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }

    private static void display(String string, List<Accounts> counts) {
        System.out.println(string+"\n");
        for(int i =0; i<counts.size(); i++){
          System.out.println("balance : "+counts.get(i).getBalance() +" owner : "+counts.get(i).getOwner()+ "idclient : "+counts.get(i).getClients().getPrenom());  
        }

    }

}